package v1

import (
	"fmt"
	"gin-vue-admin/global/response"
	"gin-vue-admin/model"
	"gin-vue-admin/model/request"
	resp "gin-vue-admin/model/response"
	"gin-vue-admin/service"
	"github.com/gin-gonic/gin"
)

// @Tags InWarehouseInfo
// @Summary 创建InWarehouseInfo
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.InWarehouseInfo true "创建InWarehouseInfo"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /InWarehouse/createInWarehouseInfo [post]
func CreateInWarehouseInfo(c *gin.Context) {
	var InWarehouse model.InWarehouseInfo
	_ = c.ShouldBindJSON(&InWarehouse)
	err := service.CreateInWarehouseInfo(InWarehouse)
	if err != nil {
		response.FailWithMessage(fmt.Sprintf("创建失败，%v", err), c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

// @Tags InWarehouseInfo
// @Summary 删除InWarehouseInfo
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.InWarehouseInfo true "删除InWarehouseInfo"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /InWarehouse/deleteInWarehouseInfo [delete]
func DeleteInWarehouseInfo(c *gin.Context) {
	var InWarehouse model.InWarehouseInfo
	_ = c.ShouldBindJSON(&InWarehouse)
	err := service.DeleteInWarehouseInfo(InWarehouse)
	if err != nil {
		response.FailWithMessage(fmt.Sprintf("删除失败，%v", err), c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// @Tags InWarehouseInfo
// @Summary 批量删除InWarehouseInfo
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除InWarehouseInfo"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /InWarehouse/deleteInWarehouseInfoByIds [delete]
func DeleteInWarehouseInfoByIds(c *gin.Context) {
	var IDS request.IdsReq
    _ = c.ShouldBindJSON(&IDS)
	err := service.DeleteInWarehouseInfoByIds(IDS)
	if err != nil {
		response.FailWithMessage(fmt.Sprintf("删除失败，%v", err), c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// @Tags InWarehouseInfo
// @Summary 更新InWarehouseInfo
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.InWarehouseInfo true "更新InWarehouseInfo"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /InWarehouse/updateInWarehouseInfo [put]
func UpdateInWarehouseInfo(c *gin.Context) {
	var InWarehouse model.InWarehouseInfo
	_ = c.ShouldBindJSON(&InWarehouse)
	err := service.UpdateInWarehouseInfo(&InWarehouse)
	if err != nil {
		response.FailWithMessage(fmt.Sprintf("更新失败，%v", err), c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// @Tags InWarehouseInfo
// @Summary 用id查询InWarehouseInfo
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.InWarehouseInfo true "用id查询InWarehouseInfo"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /InWarehouse/findInWarehouseInfo [get]
func FindInWarehouseInfo(c *gin.Context) {
	var InWarehouse model.InWarehouseInfo
	_ = c.ShouldBindQuery(&InWarehouse)
	err, reInWarehouse := service.GetInWarehouseInfo(InWarehouse.ID)
	if err != nil {
		response.FailWithMessage(fmt.Sprintf("查询失败，%v", err), c)
	} else {
		response.OkWithData(gin.H{"reInWarehouse": reInWarehouse}, c)
	}
}

// @Tags InWarehouseInfo
// @Summary 分页获取InWarehouseInfo列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.InWarehouseInfoSearch true "分页获取InWarehouseInfo列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /InWarehouse/getInWarehouseInfoList [get]
func GetInWarehouseInfoList(c *gin.Context) {
	var pageInfo request.InWarehouseInfoSearch
	_ = c.ShouldBindQuery(&pageInfo)
	err, list, total := service.GetInWarehouseInfoInfoList(pageInfo)
	if err != nil {
		response.FailWithMessage(fmt.Sprintf("获取数据失败，%v", err), c)
	} else {
		response.OkWithData(resp.PageResult{
			List:     list,
			Total:    total,
			Page:     pageInfo.Page,
			PageSize: pageInfo.PageSize,
		}, c)
	}
}
